<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<h1>
    <span class="hdr">How to integrate online editors into your own website on Java Spring</span>
</h1>

<h2>Overview</h2>
<p class="dscr">This example will help you integrate ONLYOFFICE Docs into your web application written in Java with Spring Boot.</p>
<p>Spring Boot has a lot of functionality, but its most significant features are: dependency management, auto-configuration, and built-in servlet containers.</p>

<div class="note">
    It is intended for testing purposes and demonstrating functionality of the editors.
    <b>DO NOT</b> use this integration example on your own server without proper code modifications.
    In case you enabled the test example, disable it before going for production.
</div>

<h2 id="security" class="copy-link">Important security info</h2>
<p>Please keep in mind the following security aspects when you are using test examples:</p>
<ul>
    <li>There is no protection of the storage from unauthorized access since there is no need for authorization.</li>
    <li>There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts.</li>
    <li>There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Docs.</li>
    <li>There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Docs from another domain.</li>
</ul>

<h2 id="Windows" class="copy-link">For Windows</h2>
<h2 id="win-1" class="copy-link"><span class="style_step">Step 1. </span>Install ONLYOFFICE Docs</h2>
<p>Download and install ONLYOFFICE Docs (packaged as Document Server):</p>
<div class="list-buttons">
    <a class="button" href="https://www.onlyoffice.com/download-docs.aspx?from=api#docs-developer" target="_blank">Get ONLYOFFICE Docs</a>
</div>
<p>See the detailed guide to learn how to install ONLYOFFICE Docs <a href="https://helpcenter.onlyoffice.com/installation/docs-developer-install-windows.aspx?from=api_javaspring_example" target="_blank">for Windows</a>.</p>

<h2 id="win-2" class="copy-link"><span class="style_step">Step 2. </span>Download the Java code for the editors integration</h2>
<p>Download the <a href="<%= Url.Action("demopreview") %>">Java-Spring example</a> from our site.</p>
<p>To connect the editors to your website, specify the path to the editors installation, server port and the path to the storage folder in the <em>src/main/resources/application.properties</em> file:</p>

<pre>
files.storage=
server.port=port
files.docservice.url.site=https://documentserver/
</pre>

<p>where the <b>documentserver</b> is the name of the server with the ONLYOFFICE Docs installed, <b>port</b> is any available port and <b>files.storage</b> is the path where files will be created and stored (in the project folder by default).
You can set an absolute path. For example, <em>D:\\folder</em>. Please note that on Windows OS the double backslash must be used as a separator.</p>
<p>If you want to experiment with the editor configuration, modify the <a href="<%= Url.Action("advanced") %>">parameters</a> in the <em>\src\main\webapp\editor.jsp</em> file.</p>

<h2 id="win-3" class="copy-link"><span class="style_step">Step 3. </span>Install the prerequisites</h2>
<p>To run the Java-Spring example code, install the Java version 11 appropriate for your OS and framework <b>Apache Maven</b>:</p>

<ul>
    <li><b>Java</b> (download from  <a href="https://www.oracle.com/java/technologies/downloads/#java11" target="_blank">the Oracle official website</a>);</li>
    <li><b>Apache Maven</b> (download from <a href="https://maven.apache.org/download.cgi" target="_blank">the official website</a>).</li>
</ul>

<h2 id="win-4" class="copy-link"><span class="style_step">Step 4. </span>Set environment variables</h2>
<ol>
    <li>
        <p>After you have installed Java on Windows, set the <b>JAVA_HOME</b> environment variable to point to the Java installation directory.</p>
        <p>
            Find out where Java is installed.
            If you didn't change the path during installation, it will be something like this:
        </p>

        <pre>C:\Program Files\Java\jdk11</pre>
        <p>In <b>Windows 7</b>, right click <b>My Computer</b> and select <b>Properties</b>, then click <b>Advanced</b>.</p>
        <p>In <b>Windows 8</b>, go to <b>Control Panel</b> and select <b>System</b>, then click <b>Advanced System Settings</b>.</p>
        <p>Click the <b>Environment Variables</b> button.</p>
        <p>Under <b>System Variables</b>, click <b>New</b>.</p>
        <p>In the <b>Variable Name</b> field, enter <b>JAVA_HOME</b> if you installed the <b>JDK</b> (Java Development Kit) or <b>JRE_HOME</b> if you installed the <b>JRE</b> (Java Runtime Environment).</p>
        <p>In the <b>Variable Value</b> field, enter your <b>JDK</b> or <b>JRE</b> installation path, for example <em>C:\Program Files\Java\jdk11</em>.</p>

        <p>Check if the variable created successfully by <b>echo</b> command in the <b>Command Prompt</b>:</p>
        <pre>echo %JAVA_HOME%</pre>
    </li>
    <li>
        <p>Set the <b>MAVEN_HOME</b> environment variable:</p>
        <p>Unzip the downloaded archive with Maven to any directory. It will be something like this:</p>

        <pre>C:\apache-maven-3.8.1</pre>
        <p>In <b>Windows 7</b>, right click <b>My Computer</b> and select <b>Properties</b>, then click <b>Advanced</b>.</p>
        <p>In <b>Windows 8</b>, go to <b>Control Panel</b> and select <b>System</b>, then click <b>Advanced System Settings</b>.</p>
        <p>Click the <b>Environment Variables</b> button.</p>
        <p>Under <b>System Variables</b>, click <b>New</b>.</p>
        <p>In the <b>Variable Name</b> field, enter <b>MAVEN_HOME</b>.</p>
        <p>In the <b>Variable Value</b> field, enter your <b>JDK</b> or <b>JRE</b> installation path, for example <em>C:\apache-maven-3.8.1</em>.</p>
        <p>In the system variables, find <b>PATH</b>, click the <b>Edit...</b> button. In the <b>Edit environment variable</b> dialog, click the <b>New</b> button 
            and add <em>C:\apache-maven-3.8.1\bin</em> to the <b>PATH</b> system variable.</p>

        <p>Check if the variable created successfully by <b>echo</b> command in the <b>Command Prompt</b>:</p>
        <pre>echo %MAVEN_HOME%</pre>
    </li>
</ol>


<h2 id="win-5" class="copy-link"><span class="style_step">Step 5. </span>Start application with Maven</h2>
<ol>
    <li>
        <p>Open a console and go to the <em>java-spring</em> folder using the <b>cd</b> command:</p>
        <pre>
cd C:\Program Files\document-server-integration\web\documentserver-example\java-spring
</pre>
    </li>
    <li>
        <p>In the open console, enter the following commands:</p>
        <pre>
mvn clean
mvn package
mvn spring-boot:run
</pre>
    </li>
    <li>
        <p>Open your browser using <b>server.address</b> and <b>server.port</b>:</p>
        <pre>
http://server.address:server.port/
</pre>
    </li>


<h2 id="win-6" class="copy-link"><span class="style_step">Step 6. </span>Check accessibility</h2>

<p>
    In case the example and ONLYOFFICE Docs are installed on different computers, make sure that your server with the example installed has access to the ONLYOFFICE Docs with the address which you specify instead of <b>documentserver</b> in the configuration files.
    Make sure that the ONLYOFFICE Docs in its turn has access to the server with the example installed with the address which you specify instead of <b>example.com</b> in the configuration files.
</p>

<p>If you integrated the editors successfully the result should look like the <a href="<%= Url.Action("demopreview") %>#DemoPreview">demo preview</a> on our site.</p>


<h2 id="Linux" class="copy-link">For Linux</h2>
<h2 id="linux-1" class="copy-link"><span class="style_step">Step 1. </span>Install ONLYOFFICE Docs</h2>
<p>Download and install ONLYOFFICE Docs (packaged as Document Server):</p>
<div class="list-buttons">
    <a class="button" href="https://www.onlyoffice.com/download-docs.aspx?from=api#docs-developer" target="_blank">Get ONLYOFFICE Docs</a>
</div>
<p>See the detailed guide to learn how to install ONLYOFFICE Docs <a href="https://helpcenter.onlyoffice.com/installation/docs-developer-install-ubuntu.aspx?from=api_javaspring_example" target="_blank">for Linux</a>.</p>

<h2 id="linux-2" class="copy-link"><span class="style_step">Step 2. </span>Install the prerequisites and run the website with the editors</h2>
<ol>
    <li>Install <b>Java</b> following the instructions <a href="https://docs.oracle.com/en/java/javase/20/install/installation-jdk-linux-platforms.html#GUID-737A84E4-2EFF-4D38-8E60-3E29D1B884B8" target="_blank">here</a>.
    <li>
        <p>There are two ways to get the Java-Spring example:</p>
        <ul>
            <li>
                <p>download the archive with the Java-Spring example and unpack it:</p>
                <span class="commandline">wget https://github.com/ONLYOFFICE/document-server-integration/releases/latest/download/Java.Spring.Example.zip</span>
                <span class="commandline">unzip Java.Spring.Example.zip</span>
            </li>
            <li>
                <p>clone the git repository:</p>
                <span class="commandline">git clone https://github.com/ONLYOFFICE/document-server-integration.git</span>
            </li>
        </ul>
    </li>
    <li>
        <p>Change the current directory for the project directory:</p>
        <ul>
            <li>
                <p>in the archive:</p>
                <div class="commandline">cd Java\ Spring\ Example/</div>
            </li>
            <li>
                <p>in the git repository:</p>
                <div class="commandline">cd document-server-integration/web/documentserver-example/java-spring</div>
            </li>
        </ul>
    </li>
    <li>Edit the <em>src/main/resources/application.properties</em> configuration file.
        Specify the name of your local server with the ONLYOFFICE Docs installed.
        <div class="commandline">nano src/main/resources/application.properties</div>
        <p>Edit the following lines:</p>

        <pre>
files.storage=
server.port=port
files.docservice.url.site=https://documentserver/
</pre>

        <p>where the <b>documentserver</b> is the name of the server with the ONLYOFFICE Docs installed, <b>port</b> is any available port and <b>files.storage</b> is the path where files will be created and stored (in the project folder by default). You can set an absolute path.</p>
    </li>
    <li>Install <b>Maven</b>:
        <div class="commandline">sudo apt-get install maven</div>
    </li>
    <li>Build:
        <div class="commandline">mvn package</div>
    </li>
    <li>
        <p>Start Java-Spring example:</p>
        <div class="commandline">./mvnw spring-boot:run</div>
    </li>
    <li>
        <p>Open your browser using <b>server.address</b> and <b>server.port</b>:</p>
        <div class="commandline">http://server.address:server.port/</div>
    </li>
</ol>

<h2 id="linux-3" class="copy-link"><span class="style_step">Step 3. </span>Check accessibility</h2>
<p>
    In case the example and ONLYOFFICE Docs are installed on different computers, make sure that your server with the example installed has access to the ONLYOFFICE Docs with the address which you specify instead of <b>documentserver</b> in the configuration files.
    Make sure that the ONLYOFFICE Docs in its turn has access to the server with the example installed with the address which you specify instead of <b>example.com</b> in the configuration files.
</p>

<p>If you integrated the editors successfully the result should look like the <a href="<%= Url.Action("demopreview") %>#DemoPreview">demo preview</a> on our site.</p>


<h2 id="Docker" class="copy-link">For Docker</h2>

<h2 id="docker-1" class="copy-link"><span class="style_step">Step 1. </span>Install ONLYOFFICE Docs</h2>
<p>Download and install ONLYOFFICE Docs (packaged as Document Server):</p>
<div class="list-buttons">
    <a class="button" href="https://www.onlyoffice.com/download-docs.aspx?from=api#docs-developer" target="_blank">Get ONLYOFFICE Docs</a>
</div>
<p>See the detailed guide to learn how to install ONLYOFFICE Docs <a href="https://helpcenter.onlyoffice.com/installation/docs-developer-install-docker.aspx?from=api_javaspring_example" target="_blank">for Docker</a>.</p>

<h2 id="docker-2" class="copy-link"><span class="style_step">Step 2. </span>Install the prerequisites and run the website with the editors</h2>
<ol>
    <li>Install <b>Java</b> following the instructions <a href="https://docs.oracle.com/en/java/javase/20/install/installation-jdk-linux-platforms.html#GUID-737A84E4-2EFF-4D38-8E60-3E29D1B884B8" target="_blank">here</a>.
    </li>
    <li>
        <p>There are two ways to get the Java-Spring example:</p>
        <ul>
            <li>
                <p>download the archive with the Java-Spring example and unpack it:</p>
                <span class="commandline">wget https://github.com/ONLYOFFICE/document-server-integration/releases/latest/download/Java.Spring.Example.zip</span>
                <span class="commandline">unzip Java.Spring.Example.zip</span>
            </li>
            <li>
                <p>clone the git repository:</p>
                <span class="commandline">git clone https://github.com/ONLYOFFICE/document-server-integration.git</span>
            </li>
        </ul>
    </li>
    <li>
        <p>Change the current directory for the project directory:</p>
        <ul>
            <li>
                <p>in the archive:</p>
                <div class="commandline">cd Java\ Spring\ Example/</div>
            </li>
            <li>
                <p>in the git repository:</p>
                <div class="commandline">cd document-server-integration/web/documentserver-example/java-spring</div>
            </li>
        </ul>
    </li>
    <li>Edit the <em>src/main/resources/application.properties</em> configuration file.
        Specify the name of your local server with the ONLYOFFICE Docs installed:
        <div class="commandline">nano src/main/resources/application.properties</div>
        <p>Edit the following lines:</p>

        <pre>
files.storage=
server.port=port
files.docservice.url.site=https://documentserver/ 
</pre>

        <p>where the <b>documentserver</b> is the name of the server with the ONLYOFFICE Docs installed, <b>port</b> is any available port and <b>files.storage</b> is the path where files will be created and stored (in the project folder by default).
You can set an absolute path.</p>
    </li>
    <li>Run the next command in the Java-Spring example directory:
        <div class="commandline">docker-compose up</div>
    </li>
    <li>
        <p>Open your browser using <b>server.address</b> and <b>server.port</b>:</p>
        <div class="commandline">http://server.address:server.port/</div>
    </li>
</ol>

<h2 id="docker-3" class="copy-link"><span class="style_step">Step 3. </span>Check accessibility</h2>
<p>
    In case the example and ONLYOFFICE Docs are installed on different computers, make sure that your server with the example installed has access to the ONLYOFFICE Docs with the address which you specify instead of <b>documentserver</b> in the configuration files.
    Make sure that the ONLYOFFICE Docs in its turn has access to the server with the example installed with the address which you specify instead of <b>example.com</b> in the configuration files.
</p>

<p>If you integrated the editors successfully the result should look like the <a href="<%= Url.Action("demopreview") %>#DemoPreview">demo preview</a> on our site.</p>
